import NProgress from 'nprogress';
import 'nprogress/nprogress.css'
import router from '@/router'
import {
    getToken
} from '@/utils'
NProgress.configure({
    showSpinner: false
})
// const whiteList = ['/login', '/login/register', '/login/modify']

router.beforeEach((to, from, next) => {
    NProgress.start()
    // 登录了0
    if (getToken()) {
        if (to.path == '/login') {
            next({
                path: '/'
            })
            NProgress.done()
        } else {
            next()
        }
        // 没登录
    } else {
        if (/^\/login/.test(to.path)) {
            next()
        } else {
            next('/login')
            NProgress.done()
        }
    }
});
router.afterEach(() => {
    NProgress.done()
})
